import javax.microedition.lcdui.*;
import javax.microedition.io.file.*;
import java.util.Enumeration;
public class ListRoot extends List implements CommandListener{
	private FileManagerMIDlet filemanager;
	private Command open,exit;
	private Enumeration driver;
	private Image image;;
	public ListRoot(FileManagerMIDlet fm){
		super("Mobile File Manager", Choice.IMPLICIT);	
		this.filemanager = fm;			
		char[] s = {84,104,111,225,116};
		open = new Command(new String("Mo"),Command.OK, 0);
		exit = new Command(new String(s),Command.EXIT, 0);	
		addCommand(exit);	
		addCommand(open);			
		setSelectCommand(open);
		setCommandListener(this);
		try{
			image = Image.createImage("/hdd.png");
		}
		catch(Exception e){}
		driver = FileSystemRegistry.listRoots();
		String drivername = "";
		deleteAll();
		while(driver.hasMoreElements()){
			drivername = (String) driver.nextElement();			
			append(drivername, image);
		}
		drivername = "";
	}	
	public void commandAction(Command c, Displayable d){
		if(c == open){
			String selecteddriver = getString(this.getSelectedIndex());
			filemanager.showContend("file:///" + selecteddriver, null);	
			selecteddriver = "";
		}
		if(c == exit){
			filemanager.exit();
		}		
	}
}